/*
 * COPYRIGHT. ShenZhen JiMi Technology Co., Ltd. 2017.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen JiMi Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * 2017年6月29日    Li.Shangzhi         Create the class
 * http://www.jimilab.com/
*/

package com.jimi.framework.swagger;

import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


/**
 * @FileName SwaggerDocumentationConfig.java
 * @Description: Swagger2配置类
 *
 * @Date 2017年6月29日 上午10:40:28
 * @author Li.Shangzhi
 * @version 1.0
 */
@Configuration
public class SwaggerDocumentationConfig {

	public ApiInfo apiInfo() {
		return new ApiInfoBuilder()
			.title("springboot-dubbo-samples-api")
			.description("客户端RESTful web api，提供h5、app、android的接口")
			.license("")
			.licenseUrl("")
			.termsOfServiceUrl("")
			.version("1.0.0")
			.contact(new Contact("", "", ""))
			.build();
	}

	@Bean
	public Docket createRestApi() {
//		ParameterBuilder tokenPar = new ParameterBuilder();
//		List<Parameter> pars = new ArrayList<>();
//		tokenPar.name("Authorization").description("授权的令牌").modelRef(new ModelRef("string")).parameterType("header").required(true).build();
//		tokenPar.name("accessToken").description("授权的令牌").modelRef(new ModelRef("string")).parameterType("query").required(true).build();
//		pars.add(tokenPar.build());
		return new Docket(DocumentationType.SWAGGER_2)
	        .select()
	        .paths(PathSelectors.any())
	        .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
	        .build()
//	        .globalOperationParameters(pars)
	        .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
	        .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
	        .apiInfo(apiInfo());
	}
	
}
